import entity.User;
import service.GoodsManagement;
import service.UserManagement;
import util.Result;

import java.util.Scanner;

public class Client {
    private static Scanner input = new Scanner(System.in);
    private static GoodsManagement gm = new GoodsManagement();
    //定义用户管理的对象
    private static UserManagement um = new UserManagement();
    public static void main(String[] args) {

        while (true) {
            System.out.println("************超市管理系统************");
            System.out.println("请选择：1.登录  2.注册   3.退出");
            int op = input.nextInt();
            switch (op) {
                case 1:
                    login();
                    break;
                case 2:
                    register();
                    break;
                case 3:
                    System.out.println("谢谢使用，再见！");
                    return;
            }
        }

    }

    private static void login(){
        System.out.println("请输入用户名：");
        String name = input.next();
        System.out.println("请输入密码：");
        String password = input.next();

        User user = new User(name, password);
        Result result = um.login(user);

        if (result.getCode() == 0) { //登录成功
            //进入系统
            System.out.println("进入系统");
            while (true) {
                System.out.println("1.添加或更新商品商品 2.根据编号删除 3.根据编号查询 4.根据类型查询");
                System.out.println("5.查询库存少于10的商品 6.统计最贵商品 7.销售商品 8.根据订单编号查询商品 0.退出");
                int choose = input.nextInt();
                switch (choose) {
                    case 0:
                        System.out.println("谢谢使用，再见");
                        return;
                    case 1:
                        Test2.test_add(gm);
                        break;
                    case 2:
                        Test2.test_remove(gm);
                        break;
                    case 3:
                        Test2.test_findGoodsById(gm);
                        break;
                    case 4:
                        Test2.test_findByType(gm);
                        break;
                    case 5:
                        Test2.test_storeLessThan10(gm);
                        break;
                    case 6:
                        Test2.test_getMaxGoods(gm);
                        break;
                    case 7:
                        Test2.test_sellGoods(gm);
                        break;
                    case 8:
                        Test2.test_findOrderById(gm);
                        break;
                    default:
                        System.out.println("输入有误，请重新输入");
                        break;
                }
            }
        } else {
            System.out.println(result.getNessage());
        }
    }

    private static void register(){
        System.out.println("请输入用户名：");
        String name = input.next();
        System.out.println("请输入密码：");
        String password = input.next();
        System.out.println("请输入状态：");
        int status = input.nextInt();
        User user = new User(name, password, status);

        Result result = um.addUser(user);
        System.out.println(result.getNessage());
    }
}